<?php

namespace App\Admin\Extensions;

use App\Models\SchoolInfo;
use App\Models\SchoolRoles;
use App\Models\SchoolRoleUsers;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;

class AuditPassBtn extends RowAction
{
    public $name = '通过';

    public function dialog()
    {
        $this->confirm('确定通过？');
    }

    public function handle(Model $model)
    {
        $model->status = SchoolInfo::STATUS_PASS;
        $model->save();

        $roleUserData = [
            'school_id' => $model->id,
            'user_id' => $model->user_id,
            'role_id' => SchoolRoles::MANAGER_ROLE,
        ];
        SchoolRoleUsers::create($roleUserData);
        return $this->response()->success('审批通过')->refresh();
    }

}